package com.neu.service;

import com.github.pagehelper.PageHelper;
import com.neu.dao.ShoppingRegionMapper;
import com.neu.domain.ShoppingRegion;
import com.neu.domain.ShoppingRegionExample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShoppingRegionService {
@Autowired
private ShoppingRegionMapper shoppingRegionMapper;
public List<ShoppingRegion> getAll(){
    ShoppingRegionExample example = new ShoppingRegionExample();
    byte b = 4;
    example.or().andTypeNotEqualTo(b);
    return shoppingRegionMapper.selectByExample(example);
}

public List<ShoppingRegion> queryByPid(Integer parentId) {
    ShoppingRegionExample example = new ShoppingRegionExample();
    example.or().andPidEqualTo(parentId);
    return shoppingRegionMapper.selectByExample(example);
}

public ShoppingRegion findById(Integer id) {
    return shoppingRegionMapper.selectByPrimaryKey(id);
}

public List<ShoppingRegion> querySelective(String name, Integer code, Integer page, Integer size, String sort, String order) {
    ShoppingRegionExample example = new ShoppingRegionExample();
    ShoppingRegionExample.Criteria criteria = example.createCriteria();

    if (!StringUtils.isEmpty(name)) {
        criteria.andNameLike("%" + name + "%");
    }
    if (!StringUtils.isEmpty(code)) {
        criteria.andCodeEqualTo(code);
    }

    if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
        example.setOrderByClause(sort + " " + order);
    }

    PageHelper.startPage(page, size);
    return shoppingRegionMapper.selectByExample(example);
}


}
